package structdef

import (
	"fmt"
)

type TypeDefinition struct {
	//是否是share 共享类
	IsShare bool
	// 类型名
	Name string
	//父类
	Parents []string
	// 属性
	Properties []PropertiesDefinition
	// 行为方法
	Methods map[string]BehaviorDefinition
	//类型注解
	Annotations map[string]map[string]string
}
type PropertiesDefinition struct {
	// 属性名称
	Name string
	//代码类型
	LineCodeType int
	//代码所在文件(用于日志打印)
	LineCodeFile string
	//代码所在行(用于日志打印)
	LineCodeLine int
	//类型属性注解
	Annotations map[string]map[string]string
}

// 创建属性定义
func NewPropertiesDefinition(name string, lineCodeType int, lineCodeFile string, lineCodeLine int, annotations map[string]map[string]string) PropertiesDefinition {
	return PropertiesDefinition{Name: name, LineCodeType: lineCodeType, LineCodeFile: lineCodeFile, LineCodeLine: lineCodeLine, Annotations: annotations}
}

// 创建类型定义
func NewTypeDefinition(name string, parents []string, isShare bool, properties []PropertiesDefinition, methods map[string]BehaviorDefinition, annotations map[string]map[string]string) *TypeDefinition {
	return &TypeDefinition{Name: name, Parents: parents, IsShare: isShare, Properties: properties, Methods: methods, Annotations: annotations}
}

// 实现stringer接口
func (t TypeDefinition) String() string {
	return fmt.Sprintf(`[类型名称:%s,是否是共享类:%t,类型属性:%s,类型方法:%s,类型注解:%s]`, t.Name, t.IsShare, t.Properties, t.Methods, t.Annotations)
}

// 实现stringer接口
func (p PropertiesDefinition) String() string {
	return fmt.Sprintf(`[属性名称:%s,属性类型:%d,属性所在文件:%s,属性所在行:%d,属性注解:%s]`, p.Name, p.LineCodeType, p.LineCodeFile, p.LineCodeLine, p.Annotations)
}
